package com.message.tcp.ip.application.ui.component;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.message.tcp.ip.socket.configure.entity.Case;
import com.message.tcp.ip.socket.configure.service.CaseService;

public class AcquirerPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JSplitPane splitPane;
	private JScrollPane casesPane;
	private JLabel casesLabel;
	private JScrollPane mornitorPane;
	private JLabel monitorLabel;
	private JPanel panel;
	private JMenuBar settingBar;
	private JMenu settingMenu;
	private JMenuItem settingParam;
	/**
	 * Create the panel.
	 */
	@SuppressWarnings("resource")
	public AcquirerPanel() {
		setLayout(new BorderLayout(0, 0));
		
		splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.3);
		add(splitPane);
		
		casesPane = new JScrollPane();
		splitPane.setLeftComponent(casesPane);
		
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		CaseService caseService = (CaseService) context.getBean("caseService");
		List<Case> cases = caseService.getAcqCases();
		DefaultListModel<String> model = new DefaultListModel<String>();
		for(Case c : cases){
			model.addElement(c.getName());
		}
		JList<String> list = new JList<String>(model);
		
		casesPane.setViewportView(list);
		
		casesLabel = new JLabel("Acquirer Cases");
		casesPane.setColumnHeaderView(casesLabel);
		
		mornitorPane = new JScrollPane();
		splitPane.setRightComponent(mornitorPane);
		
		monitorLabel = new JLabel("Monitor Console");
		mornitorPane.setColumnHeaderView(monitorLabel);
		
		panel = new JPanel();
		panel.setBackground(Color.WHITE);
		mornitorPane.setViewportView(panel);
		
		settingBar = new JMenuBar();
		add(settingBar, BorderLayout.NORTH);
		
		settingMenu = new JMenu("Setting");
		settingBar.add(settingMenu);
		
		settingParam = new JMenuItem("Parameter");
		settingParam.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AcquirerParamDialog dialog = new AcquirerParamDialog();
				dialog.setVisible(true);
			}
		});
		
		settingMenu.add(settingParam);

	}

}
